package com.laf.manage.controller.admin;

import cn.hutool.core.util.DesensitizedUtil;
import com.laf.common.core.controller.BaseController;
import com.laf.common.core.domain.AjaxResult;
import com.laf.common.core.page.TableDataInfo;
import com.laf.manage.domain.po.AuthInfo;
import com.laf.manage.service.IAuthInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户认证管理Controller
 *
 * @author zian
 * @date 2024-11-01
 */
@Api(tags="用户认证管理管理")
@RestController("adminAuthInfoController")
@RequestMapping("/admin/authInfo")
public class AuthInfoController extends BaseController
{
    @Autowired
    private IAuthInfoService authInfoService;

    /**
     * 查询用户认证管理列表
     */
    @ApiOperation("查询用户认证管理列表")
    @PreAuthorize("@ss.hasPermi('manage:authInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuthInfo authInfo)
    {
        startPage();
        List<AuthInfo> list = authInfoService.selectAuthInfoList(authInfo);
        for (AuthInfo info : list) {
            info.setIdNumber(DesensitizedUtil.idCardNum(info.getIdNumber(), 1, 2));
            info.setCreateBy(DesensitizedUtil.mobilePhone(info.getCreateBy()));
        }
        return getDataTable(list);
    }


    /**
     * 获取用户认证管理详细信息
     */
    @ApiOperation("获取用户认证管理详细信息")
    @PreAuthorize("@ss.hasPermi('manage:authInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(authInfoService.getById(id));
    }


    @GetMapping("isAuth/{userId}")
    @ApiOperation("判断用户是否认证")
    public AjaxResult isAuthByUserId(@PathVariable Long userId) {
       boolean flag =  authInfoService.isAuthByUserId(userId);
        return success(flag);
    }

}
